<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>拉拉货物流有限公司</title>
		<meta name="keywords" content="拉拉货物流有限公司,汕头物流配送,汕头物流,汕头物流货运,汕头货运,全国货运,厦门物流配送,深圳物流配送,广州物流配送,物流配送,物流货运,货运配送" />
	    <meta name="description" content="拉拉货物流有限公司是一家承接全国各地门到门配送业务的专业第三方物流，为企业量身定做仓储、配送物流方案，针对大小客户配备专业项目小组进行专人专车对接。" />
	    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
	    <link rel="stylesheet" href="css/amazeui.min.css" type="text/css" />
	    <link rel="stylesheet" href="css/style.css" type="text/css" />
	    <script type="text/javascript" src="js/jquery.min.js" ></script>
	    <script type="text/javascript" src="js/amazeui.min.js" ></script>
	</head>
	<body class="bgcolor">
		<header data-am-widget="header" class="am-header am-header-default header-white">
	     <div class="am-header-left am-header-nav">
	        <a href="javascript:history.back()" class=""><i class="am-icon-chevron-left"></i></a>
	     </div>
		  <h1 class="am-header-title">订单填写</h1>
	      <div class="am-header-right am-header-nav">
	      	<a href="tel:10086">帮助</a>
	      </div>
        </header>
        <div class="jl"></div>
        <h2 class="reg-title">货物信息填写</h2>
		<form>
        <ul class="reg-infor">
        	<li>
        		<em>*</em><span>货物名称：</span>
        		<i class="am-icon-angle-right"></i>
        		<input type="text" placeholder="必填" class="bt" name="goodsName"/>
        	</li>
        	<li>
        		<em>*</em><span>货物重量(KG)：</span>
        		<i class="am-icon-angle-right"></i>
        		<input type="text" placeholder="必填" class="bt" name="goodsNumber"/>
        	</li>
			<li>
				<em>*</em><span>货物体积(m³)：</span>
				<i class="am-icon-angle-right"></i>
				<input type="text" placeholder="必填" class="bt" name="goodsVolume"/>
			</li>
        	<li>
        		<em>*</em><span>接收人姓名 ：</span>
        		<i class="am-icon-angle-right"></i>
        		<input type="text" placeholder="必填" class="bt" name="consigneeName"/>
        	</li>
        	<li>
        		<em>*</em><span>接收人电话 ：</span>
        		<i class="am-icon-angle-right"></i>
        		<input type="text" placeholder="必填" class="bt" name="consigneeTel"/>
        	</li>
			<li>
				&nbsp;<span>备注 ：</span>
				<i class="am-icon-angle-right"></i>
				<input type="text" name="remake"/>
			</li>
			<div class="agree">
				是否易碎（保费500元）：
			 	<input type="checkbox" name="fragile" value="0" >&nbsp;易碎
			 </div>
			 <div class="agree">
			 	是否帮忙搬运（搬运费1000元）：
			  	<input type="checkbox" name="extra" value="0" >&nbsp;是
			  </div>
			  <input type="text" name="distance" style="display: none;">
			   <input type="text" name="startSite" style="display: none;">
			    <input type="text" name="endSite" style="display: none;">
        </ul>
		</form>
        <h2 class="reg-title">货物运输线路</h2>
        <a  class="add-rote" id="luxian">+ 添加线路</a>
        <button class="save" type="button" id="save">提交订单</button>
	</body>
	<script type="text/javascript" src="js/jquery.min.js" ></script>
	<script src="layui/layui.js"></script>
	<script>
		layui.use(['layer', 'form','jquery'], function(){
			var layer = layui.layer;
			var  $ =layui.jquery;
			var url= JSON.parse(sessionStorage.getItem("url"));
			var user= JSON.parse(sessionStorage.getItem("user"));
			if(sessionStorage.getItem("qidian")!=null&sessionStorage.getItem("qidian")!=''){
				console.log(sessionStorage.getItem("qidian"))
				$("#luxian").html(sessionStorage.getItem("qidian")+'——'+sessionStorage.getItem("zhongdian"))
			}
			//点击添加路线后存储已经填的选项
			$('#luxian').click(function(){
				
                 var arr=$("form").serializeArray();
				 var arrs=serializeToObject(arr);
				sessionStorage.setItem("orderadd", JSON.stringify(arrs))
				location.href='addroute.html'
				
			})
			//添加路线后罗列已填选项
			if(sessionStorage.getItem("orderadd")!=null){
				
			var orderadd=JSON.parse(sessionStorage.getItem("orderadd")) 
			
			console.log(orderadd)
				$('input[name=goodsName]').val(orderadd.goodsName)
				$('input[name=goodsNumber]').val(orderadd.goodsNumber)
				$('input[name=goodsVolume]').val(orderadd.goodsVolume)
				$('input[name=consigneeName]').val(orderadd.consigneeName)
				$('input[name=consigneeTel]').val(orderadd.consigneeTel)
				$('input[name=remake]').val(orderadd.remake)
				if(orderadd.fragile!=null){
					$('input[name=fragile]').attr("checked",true)
				}
				if(orderadd.extra!=null){
					$('input[name=extra]').attr("checked",true)
				}
			}
			
			$('input[name=distance]').val(sessionStorage.getItem("distance"))
			$('input[name=startSite]').val(sessionStorage.getItem("qidian"))
			$('input[name=endSite]').val(sessionStorage.getItem("zhongdian"))
			//form表单序列化为json格式
			function serializeToObject(jsonArray){
			     var o = {};
			     $.each(jsonArray, function() {
			     if (o[this.name] !== undefined) {
			      if (!o[this.name].push) {
			      o[this.name] = [o[this.name]];
			      }
			      o[this.name].push(this.value || '');
			     } else {
			      o[this.name] = this.value || '';
			     }
			     });
			     return o;
			}

			
			
			
			//订单添加
			$("#save").click(function(){
				$.ajax('',{
					url:url+"/clientOrder/save",
					data:$.param({"clientId":user.id})+'&'+$("form").serialize(),
					dataType:'json',//服务器返回json格式数据
					type:'post',//HTTP请求类型
					timeout:10000,//超时时间设置为10秒；
					success:function(data){
						if(data.code!=200){
							alert("保存失败")
						}else{
							console.log(data.data)
							sessionStorage.setItem("moneyId",data.data)
							location.href="pay.html"
							
						}
					},
				});
			})
		});
	</script>
</html>